//
//  AuctionProductDetailVC.m
//  MyNewProject
//
//  Created by 王春辉 on 2020/1/3.
//  Copyright © 2020年 sun. All rights reserved.
//

#import "AuctionProductDetailVC.h"
#import "SDCycleScrollView.h"
#import "YXLPriceHistoryViewController.h"
#import "XMJSWebViewController.h"
#import "CertifyViewController.h"
#import <WebKit/WebKit.h>
#import "BAKit_WebView.h"

#pragma mark -- mark 数据相关
#import "AuctionDetailModel.h"

@interface AuctionProductDetailVC ()<SDCycleScrollViewDelegate> {
    UIButton *_buyBtn;
    NSTimer *_timer;
    
    NSDate *_endDate;// 结束时间
    AuctionDetailDataModel *_dataModel;
    NSString *_ptType; // 类型
    NSString *_referPrice; // 出价
    BOOL _canChoose; // 是否可以出价
    NSTimeInterval _sinceStartTime;
    NSTimeInterval _sinceEndTime;
    NSInteger _status; // 产品状态
}
@property (nonatomic, strong) UIScrollView *scrollView;

/**
 滚动banner
 */
@property (nonatomic, strong) SDCycleScrollView *bannerView;

/**
 title
 */
@property (nonatomic, strong) UILabel *titleLabel;

/**
 价格
 */
@property (nonatomic, strong) UILabel *priceLabel;

/**
 倒计时label
 */
@property (nonatomic, strong) UILabel *countDownLabel;

/**
 是否可以竞拍
 */
@property (nonatomic, assign, setter=setIsCanMakeOffer:) BOOL isCanMakeOffer;

/**
 保证金
 */
@property (nonatomic, strong) UILabel *depositLabel;

/**
 起拍价
 */
@property (nonatomic, strong) UILabel *lowpriceLabel;

/**
 加价幅度
 */
@property (nonatomic, strong) UILabel *raisepriceLabel;

/**
 开始时间
 */
@property (nonatomic, strong) UILabel *startDateLabel;

/**
 结束时间
 */
@property (nonatomic, strong) UILabel *endDateLabel;

/// 委托方
@property (nonatomic, strong) UILabel *salerLabel;

/**
 参考价
 */
@property (nonatomic, strong) UILabel *advicePriceLabel;

///  分享按钮view
@property (nonatomic, strong) UIView *shareButtonView;

/**
 展示html文件
 */
@property (nonatomic, strong) WKWebView *webView;
@end

@implementation AuctionProductDetailVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.gk_navTitle = @"拍品详情";
    self.view.backgroundColor = SKColorWithHex(0xF1F1F1);
    [self initContentViews];
}
- (void)viewDidDisappear:(BOOL)animated {
    [super viewDidDisappear:animated];
    [self invalidateTimer];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self requestData];
}
- (void)initContentViews {
    CGFloat margin = 15.0;
    
    UIButton *butNowBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [butNowBtn setTitle:@"我要竞拍" forState:UIControlStateNormal];
    [butNowBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    butNowBtn.titleLabel.font = SKFONT_BOLD_SIZE(19);
    butNowBtn.backgroundColor = SKColorWithHex(0xE33030);
    [butNowBtn addTarget:self action:@selector(makeOfferButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:butNowBtn];
    _buyBtn = butNowBtn;
    [butNowBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.bottom.mas_offset(-SKBottomSafe_Height);
        make.height.mas_equalTo(butNowBtn.mas_width).multipliedBy(49.0/375);
    }];
    
    [self.scrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_offset(0);
        make.width.mas_equalTo(self.view.mas_width);
        make.top.mas_offset(SKTopBar_Height);
        if (self.showType == AuctionProductDetailTypeLog) {
            make.bottom.mas_offset(-SKBottomSafe_Height);
        }else {
            make.bottom.mas_equalTo(butNowBtn.mas_top).mas_offset(0);
        }
    }];
    
    [self.scrollView addSubview:self.bannerView];
    [self.bannerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.top.mas_offset(0);
        make.width.mas_equalTo(self.view.mas_width);
        make.height.mas_equalTo(self.bannerView.mas_width).multipliedBy(287.5 / 375);
    }];
    
    UIView *view1 = [[UIView alloc] init];
    view1.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view1];
    [view1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(self.bannerView);
        make.top.mas_equalTo(self.bannerView.mas_bottom);
        make.height.mas_equalTo(view1.mas_width).multipliedBy(77.5 / 375);
    }];
    
    UILabel *tipLabel1 = [[UILabel alloc] init];
    tipLabel1.text = @"现价：";
    tipLabel1.textColor = self.priceLabel.textColor;
    tipLabel1.font = SKFONT_SIZE(13);
    [view1 addSubview:tipLabel1];
    [view1 addSubview:self.titleLabel];
    [view1 addSubview:self.priceLabel];
    [view1 addSubview:self.countDownLabel];
    
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(margin);
        make.right.mas_offset(-margin);
        make.bottom.mas_equalTo(view1.mas_centerY).mas_offset(-10);
    }];
    
    [tipLabel1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.top.mas_equalTo(view1.mas_centerY).mas_offset(12);
    }];
    
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel1.mas_right).mas_offset(4);
        make.bottom.mas_equalTo(tipLabel1.mas_bottom).mas_offset(2);
        make.right.mas_lessThanOrEqualTo(-margin);
    }];
    
    [self.countDownLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-margin);
        make.centerY.mas_equalTo(tipLabel1);
    }];
    
    UIView *view2 = [[UIView alloc] init];
    view2.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view2];
    [view2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(view1);
        make.top.mas_equalTo(view1.mas_bottom).mas_offset(10);
        make.height.mas_equalTo(view2.mas_width).multipliedBy(60.0/375);
    }];
    
    UILabel *tipLabel2_1 = [[UILabel alloc] init];
    tipLabel2_1.text = @"保证金";
    tipLabel2_1.textColor = SKColorWithHex(0x999999);
    tipLabel2_1.font = SKFONT_SIZE(14);
    [view2 addSubview:tipLabel2_1];
    
    UILabel *tipLabel2_2 = [[UILabel alloc] init];
    tipLabel2_2.text = @"起拍价";
    tipLabel2_2.textColor = SKColorWithHex(0x999999);
    tipLabel2_2.font = SKFONT_SIZE(14);
    [view2 addSubview:tipLabel2_2];
    
    UILabel *tipLabel2_3 = [[UILabel alloc] init];
    tipLabel2_3.text = @"加价幅度";
    tipLabel2_3.textColor = SKColorWithHex(0x999999);
    tipLabel2_3.font = SKFONT_SIZE(14);
    [view2 addSubview:tipLabel2_3];
    
    UIView *line2_1 = [[UIView alloc] init];
    line2_1.backgroundColor = self.view.backgroundColor;
    [view2 addSubview:line2_1];
    
    UIView *line2_2 = [[UIView alloc] init];
    line2_2.backgroundColor = self.view.backgroundColor;
    [view2 addSubview:line2_2];
    [view2 addSubview:self.depositLabel];
    [view2 addSubview:self.lowpriceLabel];
    [view2 addSubview:self.raisepriceLabel];
    
    [self.depositLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_offset(0);
        make.right.mas_equalTo(line2_1.mas_left).mas_offset(0);
        make.bottom.mas_equalTo(view2.mas_centerY).mas_offset(0);
        make.width.mas_equalTo(self.lowpriceLabel);
        make.width.mas_equalTo(self.raisepriceLabel);
        make.bottom.mas_equalTo(self.lowpriceLabel);
        make.bottom.mas_equalTo(self.raisepriceLabel);
    }];
    [line2_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
        make.width.mas_equalTo(0.5);
    }];
    
    [self.lowpriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(line2_1.mas_right).mas_offset(0);
        make.right.mas_equalTo(line2_2.mas_left).mas_offset(0);
    }];
    [line2_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.bottom.mas_offset(0);
        make.width.mas_equalTo(0.5);
    }];
    [self.raisepriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(line2_2.mas_right).mas_offset(0);
        make.right.mas_offset(0);
    }];
    
    [tipLabel2_1 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.depositLabel.mas_bottom);
        make.centerX.mas_equalTo(self.depositLabel);
    }];
    
    [tipLabel2_2 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tipLabel2_1);
        make.centerX.mas_equalTo(self.lowpriceLabel);
    }];
    
    [tipLabel2_3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(tipLabel2_1);
        make.centerX.mas_equalTo(self.raisepriceLabel);
    }];
    
    UIView *view3 = [[UIView alloc] init];
    view3.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view3];
    [view3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(view1);
        make.top.mas_equalTo(view2.mas_bottom).mas_offset(10);
        make.height.mas_equalTo(view3.mas_width).multipliedBy(45.0 / 375);
    }];
    
    UILabel *tipLabel3 = [[UILabel alloc] init];
    tipLabel3.text = @"开始时间";
    tipLabel3.font = SKFONT_SIZE(14);
    tipLabel3.textColor = SKColorWithHex(0x999999);
    [view3 addSubview:tipLabel3];
    [view3 addSubview:self.startDateLabel];
    [tipLabel3 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.centerY.mas_offset(0);
    }];
    [self.startDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-margin);
        make.centerY.mas_offset(0);
    }];
    
    UIView *view4 = [[UIView alloc] init];
    view4.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view4];
    [view4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(view3);
        make.top.mas_equalTo(view3.mas_bottom).mas_offset(0.5);
    }];
    UILabel *tipLabel4 = [[UILabel alloc] init];
    tipLabel4.text = @"结束时间";
    tipLabel4.font = SKFONT_SIZE(14);
    tipLabel4.textColor = SKColorWithHex(0x999999);
    [view4 addSubview:tipLabel4];
    [view4 addSubview:self.endDateLabel];
    [tipLabel4 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel3);
        make.centerY.mas_offset(0);
    }];
    [self.endDateLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.startDateLabel);
        make.centerY.mas_offset(0);
    }];
    
    UIView *salerView = [[UIView alloc] init];
    salerView.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:salerView];
    [salerView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(view2);
        make.top.mas_equalTo(view4.mas_bottom).mas_offset(0.5);
    }];
    UILabel *salerTipLabel = [[UILabel alloc] init];
    salerTipLabel.font = tipLabel4.font;
    salerTipLabel.textColor = tipLabel4.textColor;
    salerTipLabel.text = @"委托方";
    [salerView addSubview:salerTipLabel];
    [salerView addSubview:self.salerLabel];
    [salerTipLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.centerY.mas_offset(0);
    }];
    [self.salerLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.endDateLabel);
        make.centerY.mas_offset(0);
    }];
    
    UIView *view5 = [[UIView alloc] init];
    view5.backgroundColor = [UIColor whiteColor];
    [self.scrollView addSubview:view5];
    [view5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(view3);
        make.top.mas_equalTo(salerView.mas_bottom).mas_offset(0.5);
    }];
    UILabel *tipLabel5 = [[UILabel alloc] init];
    tipLabel5.text = @"市场参考价";
    tipLabel5.font = SKFONT_SIZE(14);
    tipLabel5.textColor = SKColorWithHex(0x999999);
    [view5 addSubview:tipLabel5];
    [view5 addSubview:self.advicePriceLabel];
    [tipLabel5 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel4);
        make.centerY.mas_offset(0);
    }];
    [self.advicePriceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.startDateLabel);
        make.centerY.mas_offset(0);
    }];
    
    UIView *view6 = [[UIView alloc] init];
    view6.tag = 5206;
    view6.backgroundColor = [UIColor whiteColor];
    UIButton *btn6 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn6 addTarget:self action:@selector(sellLogButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [view6 addSubview:btn6];
    [self.scrollView addSubview:view6];
    [view6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(view3);
        make.top.mas_equalTo(view5.mas_bottom).mas_offset(0.5);
    }];
    [btn6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    UILabel *tipLabel6 = [[UILabel alloc] init];
    tipLabel6.text = @"出价记录";
    tipLabel6.font = SKFONT_SIZE(14);
    tipLabel6.textColor = SKColorWithHex(0x999999);
    [view6 addSubview:tipLabel6];
    UIImageView *imageView6 = [[UIImageView alloc] initWithImage:SKIMAGE_NAMED(@"rightArrow")];
    [view6 addSubview:imageView6];
    [tipLabel6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel4);
        make.centerY.mas_offset(0);
    }];
    [imageView6 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.startDateLabel);
        make.centerY.mas_offset(0);
    }];
    
    UIView *view7 = [[UIView alloc] init];
    view7.tag = 5207;
    view7.backgroundColor = [UIColor whiteColor];
    UIButton *btn7 = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn7 addTarget:self action:@selector(sellDetailButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [view7 addSubview:btn7];
    [self.scrollView addSubview:view7];
    [view7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.height.mas_equalTo(view3);
        make.top.mas_equalTo(view6.mas_bottom).mas_offset(0.5);
    }];
    [btn7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.mas_offset(0);
    }];
    
    UILabel *tipLabel7 = [[UILabel alloc] init];
    tipLabel7.text = @"竞拍规则";
    tipLabel7.font = SKFONT_SIZE(14);
    tipLabel7.textColor = SKColorWithHex(0x999999);
    [view7 addSubview:tipLabel7];
    UIImageView *imageView7 = [[UIImageView alloc] initWithImage:SKIMAGE_NAMED(@"rightArrow")];
    [view7 addSubview:imageView7];
    [tipLabel7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(tipLabel4);
        make.centerY.mas_offset(0);
    }];
    [imageView7 mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.startDateLabel);
        make.centerY.mas_offset(0);
    }];
    
    [self.shareButtonView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(butNowBtn.mas_top).mas_offset(-10);
    }];
    [self.scrollView addSubview:self.webView];
    [self.webView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.mas_equalTo(view7);
        make.top.mas_equalTo(view7.mas_bottom).mas_offset(10);
        make.bottom.mas_offset(0);
    }];
    [self.view bringSubviewToFront:self.shareButtonView];
    
    if (self.showType == AuctionProductDetailTypeLog) {
        self.shareButtonView.hidden = true;
    }
}

#pragma mark -- mark 懒加载

- (UIScrollView *)scrollView {
    if (!_scrollView) {
        _scrollView = [[UIScrollView alloc] init];
        _scrollView.backgroundColor = self.view.backgroundColor;
        [self.view addSubview:_scrollView];
    }
    return _scrollView;
}

- (SDCycleScrollView *)bannerView {
    if (!_bannerView) {
        _bannerView = [SDCycleScrollView cycleScrollViewWithFrame:CGRectZero delegate:self placeholderImage:SKIMAGE_NAMED(@"bannerPlacehoder")];
        _bannerView.currentPageDotImage = SKIMAGE_NAMED(@"shop_banner_pagecontrol_current_img");
        _bannerView.pageDotImage = SKIMAGE_NAMED(@"shop_banner_pagecontrol_default_img");
        _bannerView.bannerImageViewContentMode = UIViewContentModeScaleAspectFit;
        _bannerView.infiniteLoop = true;
    }
    return _bannerView;
}

- (UILabel *)titleLabel {
    if (!_titleLabel) {
        _titleLabel = [[UILabel alloc] init];
        _titleLabel.font = SKFONT_BOLD_SIZE(18);
        _titleLabel.textColor = SKColorWithHex(0x333333);
        _titleLabel.text = @" ";
    }
    return _titleLabel;
}

- (UILabel *)priceLabel {
    if (!_priceLabel) {
        _priceLabel = [[UILabel alloc] init];
        _priceLabel.font = SKFONT_Medium(16);
        _priceLabel.textColor = SKColorWithHex(0xFF3030);
        _priceLabel.text = @" ";
    }
    return _priceLabel;
}
- (UILabel *)countDownLabel {
    if (!_countDownLabel) {
        _countDownLabel = [[UILabel alloc] init];
        _countDownLabel.font = SKFONT_SIZE(13);
        _countDownLabel.textColor = SKColorWithHex(0x888888);
        _countDownLabel.text = @" ";
    }
    return _countDownLabel;
}
- (UILabel *)depositLabel {
    if (!_depositLabel) {
        _depositLabel = [[UILabel alloc] init];
        _depositLabel.font = SKFONT_SIZE(14);
        _depositLabel.textColor = SKColorWithHex(0x333333);
        _depositLabel.text = @" ";
        _depositLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _depositLabel;
}

- (UILabel *)lowpriceLabel {
    if (!_lowpriceLabel) {
        _lowpriceLabel = [[UILabel alloc] init];
        _lowpriceLabel.font = SKFONT_SIZE(14);
        _lowpriceLabel.textColor = SKColorWithHex(0x333333);
        _lowpriceLabel.text = @" ";
        _lowpriceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _lowpriceLabel;
}
- (UILabel *)raisepriceLabel {
    if (!_raisepriceLabel) {
        _raisepriceLabel = [[UILabel alloc] init];
        _raisepriceLabel.font = SKFONT_SIZE(14);
        _raisepriceLabel.textColor = SKColorWithHex(0x333333);
        _raisepriceLabel.text = @" ";
        _raisepriceLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _raisepriceLabel;
}
- (UILabel *)startDateLabel {
    if (!_startDateLabel) {
        _startDateLabel = [[UILabel alloc] init];
        _startDateLabel.textColor = SKColorWithHex(0x999999);
        _startDateLabel.font = SKFONT_SIZE(14);
        _startDateLabel.text = @" ";
    }
    return _startDateLabel;
}

- (UILabel *)endDateLabel {
    if (!_endDateLabel) {
        _endDateLabel = [[UILabel alloc] init];
        _endDateLabel.textColor = SKColorWithHex(0x999999);
        _endDateLabel.font = SKFONT_SIZE(14);
        _endDateLabel.text = @" ";
    }
    return _endDateLabel;
}
- (UILabel *)salerLabel {
    if (!_salerLabel) {
        _salerLabel = [[UILabel alloc] init];
        _salerLabel.font = SKFONT_SIZE(14);
        _salerLabel.textColor = SKColorWithHex(0x999999);
        _salerLabel.text = @" ";
    }
    return _salerLabel;
}
- (UILabel *)advicePriceLabel {
    if (!_advicePriceLabel) {
        _advicePriceLabel = [[UILabel alloc] init];
        _advicePriceLabel.textColor = SKColorWithHex(0x999999);
        _advicePriceLabel.font = SKFONT_SIZE(14);
        _advicePriceLabel.text = @" ";
    }
    return _advicePriceLabel;
}
- (UIView *)shareButtonView {
    if (!_shareButtonView) {
        _shareButtonView = [[UIView alloc] initWithFrame:CGRectZero];
        _shareButtonView.layer.masksToBounds = true;
        _shareButtonView.layer.borderWidth = 0.5;
        _shareButtonView.layer.borderColor = [UIColor lightGrayColor].CGColor;
        _shareButtonView.layer.shadowColor = [UIColor cyanColor].CGColor;
        _shareButtonView.layer.shadowOpacity = 0.5;
        _shareButtonView.layer.shadowOffset = CGSizeMake(20, 20);
        _shareButtonView.backgroundColor = [UIColor colorWithRed:1.0 green:1.0 blue:1.0 alpha:0.8];
        _shareButtonView.layer.cornerRadius = 20.0;
        [self.view addSubview:_shareButtonView];
        [_shareButtonView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.right.mas_offset(-15);
            make.size.mas_equalTo(CGSizeMake(40, 40));
        }];
        UIButton *shareButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [shareButton setImage:SKIMAGE_NAMED(@"shop_share_btn_img_1") forState:UIControlStateNormal];
        [shareButton addTarget:self action:@selector(shareButtonClick:) forControlEvents:UIControlEventTouchUpInside];
        [_shareButtonView addSubview:shareButton];
        [shareButton mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(0);
        }];
    }
    return _shareButtonView;
}
- (WKWebView *)webView {
    if (!_webView)
    {
        _webView = [WKWebView new];
        _webView.ba_web_isAutoHeight = YES;
        //  添加 WKWebView 的代理，注意：用此方法添加代理
        BAKit_WeakSelf
        [_webView ba_web_initWithDelegate:weak_self.webView uIDelegate:weak_self.webView];
        _webView.backgroundColor = [UIColor whiteColor];
        _webView.userInteractionEnabled = true;
        _webView.ba_web_getCurrentHeightBlock = ^(CGFloat currentHeight) {
            BAKit_StrongSelf
            [self.webView mas_updateConstraints:^(MASConstraintMaker *make) {
                make.height.mas_equalTo(currentHeight);
            }];
            [self.scrollView layoutIfNeeded];
        };
    }
    return _webView;
}
#pragma mark -- mark 业务逻辑

/**
 初始化timer
 */
- (void)setupTimer {
    [self invalidateTimer];
    NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(countDown:) userInfo:nil repeats:YES];
    _timer = timer;
    [[NSRunLoop mainRunLoop] addTimer:timer forMode:NSRunLoopCommonModes];
}

/**
 停止计时器
 */
- (void)invalidateTimer {
    [_timer invalidate];
    _timer = nil;
}
- (void)dealloc {
    [self invalidateTimer];
}
/**
 倒计是

 @param timer timer
 */
- (void)countDown:(NSTimer *)timer {
    if (_status == 1) {
        // 未开始
        if (_sinceStartTime <= 0) {
            [self invalidateTimer];
            [self requestData];
            self.isCanMakeOffer = false;
            return;
        }else {
            _sinceStartTime -= 1;
            int hour = (int)_sinceStartTime / (3600);
            int minute = ((int)_sinceStartTime % (3600)) / 60;
            int second = ((int)_sinceStartTime % (3600)) % 60;
            self.countDownLabel.text = [NSString stringWithFormat:@"竞拍倒计时：%02d:%02d:%02d", hour, minute, second];
        }
    }else if (_status == 2) {
        // 进行中
        if (_sinceEndTime <= 0) {
            [self invalidateTimer];
            [self requestData];
            self.isCanMakeOffer = false;
            return;
        }else {
            _sinceEndTime -= 1;
            int hour = (int)_sinceEndTime / (3600);
            int minute = ((int)_sinceEndTime % (3600)) / 60;
            int second = ((int)_sinceEndTime % (3600)) % 60;
            self.countDownLabel.text = [NSString stringWithFormat:@"竞拍倒计时：%02d:%02d:%02d", hour, minute, second];
        }
    }else {
        [self invalidateTimer];
        self.isCanMakeOffer = false;
    }
}

/**
 是否可以竞拍

 @param isCanMakeOffer isCanMakeOffer
 */
- (void)setIsCanMakeOffer:(BOOL)isCanMakeOffer {
    _isCanMakeOffer = isCanMakeOffer;
    _buyBtn.enabled = isCanMakeOffer;
}

#pragma mark -- mark 获取网络数据

- (void)requestData {
    SKWeakSelf;
    if (!self.sellId) {
        [self debugShowMessage:@"无效的id"];
        return; }
    _canChoose = false;
    [YQNetworking getWithUrl:@"Index/getSellInfo" params:@{@"sell_id":self.sellId} reloginRefreshBlock:^(id response) {
        
    } successBlock:^(id response) {
        AuctionDetailModel *model = [AuctionDetailModel modelWithDictionary:response];
        if ([model isSuccess]) {
            [weakSelf refreshContentViewWith:model.data];
        }else {
            [weakSelf showMessage:model.msg];
        }
    } failBlock:^(NSError *error) {
        [weakSelf debugShowMessage:error.localizedDescription];
    }];
}


/// 刷新数据
/// @param model model
- (void)refreshContentViewWith:(AuctionDetailDataModel *)model {
    _dataModel = model;
    // 轮播图数据
    NSArray <AuctionDetailDataBannerModel *>*banners = model.lunbo;
    NSMutableArray <NSString *>*mArr = [NSMutableArray<NSString *> arrayWithCapacity:banners.count];
    for (AuctionDetailDataBannerModel *bannerModel in banners) {
        [mArr addObject:bannerModel.imgurl];
    }
    self.bannerView.imageURLStringsGroup = mArr;
    
    // 数据info
    AuctionDetailDataInfoModel *infoModel = model.sell_info;
    self.titleLabel.text = infoModel.title;
    self.priceLabel.text = [NSString stringWithFormat:@"%@元", infoModel.price];
    self.startDateLabel.text = infoModel.begin_time;
    self.endDateLabel.text = infoModel.end_time;
    self.depositLabel.text = infoModel.bail;
    self.lowpriceLabel.text = infoModel.begin_price;
    self.raisepriceLabel.text = infoModel.range;
    self.salerLabel.text = infoModel.supplier;
    self.advicePriceLabel.text = [NSString stringWithFormat:@"¥ %@", infoModel.refer_price];
    NSString *html = infoModel.contents;
    [self.webView loadHTMLString:html baseURL:[NSURL URLWithString:@"http://hxapi.yupinyouxuan.com"]];
    int status = [infoModel.status intValue];
    // 1未开始 2进行中 3已结束 4已成交
    if (status == 1 && [infoModel.lost_begin_time doubleValue] > 0) {
        // 未开始
        _sinceStartTime = [infoModel.lost_begin_time doubleValue];
        [self setupTimer];
        self.isCanMakeOffer = false;
    }else if (status == 2 && [infoModel.lost_end_time doubleValue] > 0) {
        // 进行中
        _sinceEndTime = [infoModel.lost_end_time doubleValue];
        [self setupTimer];
        self.isCanMakeOffer = true;
    }else if (status == 3) {
        // 已结束
        self.countDownLabel.text = @"已结束";
        self.isCanMakeOffer = true;
    }else if (status == 4) {
        // 已成交
        self.countDownLabel.text = @"已成交";
        self.isCanMakeOffer = true;
    }else if (status == 5) {
        // 流拍
        self.countDownLabel.text = @"已结束";
        self.isCanMakeOffer = false;
    }else {}
    
    if (model.sell_log.ID && (status != 5)) {
        // 有拍卖得主 并且没有流派
        // 展示 拍卖纪录view
        
    }else {
        // 隐藏 拍卖纪录界面
        UIView *view6 = [self.scrollView viewWithTag:5206];
        UIView *view7 = [self.scrollView viewWithTag:5207];
        [view7 mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.left.right.height.top.mas_equalTo(view6);
        }];
    }
    NSString *btnTitle;
    if (status == 1) {
        btnTitle = @"即将开始";
    }else if (status == 2) {
        btnTitle = @"我要竞拍";
    }else if (status == 3 || status == 4) {
        btnTitle = @"查看会场";
    }else if (status == 5) {
        btnTitle = @"已结束";
    }else {}
    _canChoose = _buyBtn.isEnabled;
    [_buyBtn setTitle:btnTitle forState:UIControlStateNormal];
    _status = status;
    _ptType = [NSString stringWithFormat:@"%d", status];
    _referPrice = model.sell_info.refer_price;
}


#pragma mark -- mark EVENT

// 出价记录
- (void)sellLogButtonClick:(UIButton *)sender {
    // 跳转出价记录界面
    YXLPriceHistoryViewController *vc = [[YXLPriceHistoryViewController alloc] init];
    vc.sell_Type = [_ptType intValue];
    vc.sell_id = self.sellId;
    vc.refer_price = _referPrice;
    [self.navigationController pushViewController:vc animated:true];
}

/// 查看详情
/// @param sender sender
- (void)sellDetailButtonClick:(UIButton *)sender {
    SKWeakSelf;
    [YQNetworking getWithUrl:@"Index/getNotice" params:@{@"type":@(7)} reloginRefreshBlock:^(id response) {
        
    } successBlock:^(id response) {
        WJBaseModel *model = [WJBaseModel modelWithDictionary:response];
        if ([model isSuccess]) {
            XMJSWebViewController * webVC = [[XMJSWebViewController alloc]init];
            webVC.type = WebType_H5_content;
            webVC.titleString = SafeString(@"竞拍规则");
            NSArray *data = response[@"data"];
            NSDictionary *info = [data firstObject];
            NSString *contents = info[@"contents"];
            webVC.fileUrl = contents;
            [weakSelf.navigationController pushViewController:webVC animated:YES];
        }else {
            [weakSelf showMessage:model.msg];
        }
    } failBlock:^(NSError *error) {
        [weakSelf debugShowMessage:error.localizedDescription];
    }];
}

/// 分享按钮
/// @param sender sender
- (void)shareButtonClick:(UIButton *)sender {
    NSString *reg_num = [UserInfoSingleton shareInstance].userInfo.reg_num;
    reg_num = (reg_num.length > 0) ? reg_num : @"aaaaaa";
    [AppDelegate wj_wxShareWith:reg_num PtNum:self.sellId SellOrGoodId:true Complete:^(BOOL status) {
        
    }];
}
/**
 出价竞拍

 @param sender sender
 */
- (void)makeOfferButtonClick:(UIButton *)sender {
    if (!_canChoose) {
        return; }
    // 跳转出价记录界面
    SKWeakSelf;
    [self checkIsRealLoginComplete:^(BOOL isLogin) {
        if (isLogin) {
            [weakSelf makeSureCertify];
        }
    }];
}

/// 是否实名认证
- (void)makeSureCertify {
    SKWeakSelf;
    [self checkIsRealCertifyComplete:^(BOOL success) {
        if (success) {
            [weakSelf auction];
        }
    }];
}
/**
 去竞拍
 */
- (void)auction {
    YXLPriceHistoryViewController *vc = [[YXLPriceHistoryViewController alloc] init];
    vc.sell_Type = [_ptType intValue];
    vc.sell_id = self.sellId;
    vc.refer_price = _referPrice;
    [self.navigationController pushViewController:vc animated:true];
}

/// 检测是否已登陆
/// @param complete complete
- (void)checkIsRealLoginComplete:(void(^)(BOOL))complete {
    BOOL isLogin = [[UserInfoSingleton shareInstance].userInfo isLogin];
    if (isLogin) {
        if (complete) {
            complete(true);
        }
    }else {
        // 未登录
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"抱歉！你还未登录，请登录后开始竞拍" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (complete) {
                complete(false);
            }
        }];
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"登录" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            [AppDelegate pushLoginViewComplete:^(id model) {
                if (complete) {
                    complete(true);
                }
            }];
        }];
        [alert addAction:cancel];
        [alert addAction:sure];
        [self presentViewController:alert animated:true completion:nil];
    }
}

/**
 检测是否实名认证

 @param complete complete
 */
- (void)checkIsRealCertifyComplete:(void(^)(BOOL))complete {
    BOOL isRealCerty = [[UserInfoSingleton shareInstance].userInfo isRealCertify];
    if (isRealCerty) {
        // 已认证
        if (complete) {
            complete(true); }
    }else {
        // 未认证
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"" message:@"抱歉！你还未实名认证，无法参加竞价" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *cancel = [UIAlertAction actionWithTitle:@"算了" style:UIAlertActionStyleCancel handler:^(UIAlertAction * _Nonnull action) {
            if (complete) {
                complete(false);
            }
        }];
        UIAlertAction *sure = [UIAlertAction actionWithTitle:@"去认证" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            CertifyViewController *vc = [[CertifyViewController alloc] init];
            vc.certifyResultBlock = ^(BOOL success) {
                if (complete) {
                    complete(success); }
            };
            [self.navigationController pushViewController:vc animated:true];
        }];
        [alert addAction:cancel];
        [alert addAction:sure];
        [self presentViewController:alert animated:true completion:nil];
    }
}
@end
